local sk__xingxue = fk.CreateSkill {

  name = "sk__xingxue",

  tags = {  },

}



sk__xingxue:addEffect(fk.EventPhaseStart, {
  name = "sk__xingxue",
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__xingxue.name) and player.phase == Player.Finish and
      table.find(player.room.alive_players, function(p)
        return p:getMark("@sk__yanzhu") > 0
      end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room.alive_players, function(p)
      return p:getMark("@sk__yanzhu") > 0
    end), Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#sk__xingxue-choose", sk__xingxue.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    to:drawCards(to:getMark("@sk__yanzhu"), sk__xingxue.name)
    if to ~= player and not to.dead and not player.dead and to:getHandcardNum() > to.maxHp then
      local n = to:getHandcardNum() - to.maxHp
      local cards = room:askForCard(to, n, n, false, sk__xingxue.name, false, ".", "#sk__xingxue-give:"..player.id.."::"..n)
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonGive, sk__xingxue.name, nil, false, to)
    end
    if not to.dead then
      room:setPlayerMark(to, "@sk__yanzhu", 0)
    end
  end,
})

return sk__xingxue